import sounddevice as sd
import numpy as np

# 设置录音参数
fs = 16000  # 采样率
duration = 5  # 录音时长（秒）

# 开始录音
# print("开始录音...")
audio_data = sd.rec(int(duration * fs), samplerate=fs, channels=1, dtype='int16')
sd.wait()  # 等待录音完成
# print("录音结束")

# 将录音数据保存为 PCM 文件
pcm_file = "../pcmfiles/receivedPcmData.pcm"
audio_data.tofile(pcm_file)
# print(f"录音数据已保存到 {pcm_file}")

print("录音完成")